package com.lz.test;

import com.lz.test.pojo.UserDTO;
import com.lz.test.pojo.UserVO;

import java.util.List;
import java.util.Map;

/**
 * @description
 *
 * @date 2021-11-23 15:17
 *
 * @author Lizhong
 */
public class UserService02 {

    UserDao userDao;

    public UserVO getUserByIdStatic(int uid){
        List<UserDTO> users = userDao.getUserInfo();
        UserDTO userDTO = users.stream().filter(u -> u.getId() == uid).findFirst().orElse(null);
        UserVO userVO = new UserVO();
        if(null == userDTO){
            return userVO;
        }
        userVO.setId(userDTO.getId());
        userVO.setName(userDTO.getName());
        userVO.setSex(userDTO.getSex());
        if("上海".equals(userDTO.getProvince())){
            userVO.setAbbreviation("沪");
            userVO.setPostCode(200000);
        }
        if("北京".equals(userDTO.getProvince())){
            userVO.setAbbreviation("京");
            userVO.setPostCode(100000);
        }
        if(null != userDTO.getTelephone() && !"".equals(userDTO.getTelephone())){
            userVO.setTelephone(userDTO.getTelephone().substring(0,3)+"****"+userDTO.getTelephone().substring(7));
        }
        // 静态方法调用 身份证工具类
        Map<String, String> idMap = IDNumberUtils.getBirAgeSex(userDTO.getIdNo());
        userVO.setAge(idMap.get("age")!=null ? Integer.parseInt(idMap.get("age")) : 0);
        // 静态方法调用 记录日志
        LogUtils.info("response user:", userVO.toString());
        return userVO;
    }
}
